package com.shopping.handler;

import com.alibaba.fastjson2.JSONObject;
import com.shopping.commons.Result;
import org.springframework.security.core.Authentication;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import java.io.IOException;
/**
 * 退出成功处理器，该处理器实现LogoutSuccessHandler
 *  当用户登陆成功后会自动执行该处理器里的onLogoutSuccess方法
 */
public class LogoutSuccessHandlerImpl implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().println(JSONObject.toJSONString(Result.success("退出成功!!!")));
    }
}
